package main.java.com.chankudo.annotation;

import java.lang.reflect.Method;
import java.lang.annotation.Annotation;

/**
 * 程序运行时,根据注解的情况,自行决定做接下来的操作.
 */
public class AnalyzeAnnotation {
    public static void main(String[] args) throws ClassNotFoundException {
        Class useAnnClz = Class.forName("main.java.com.chankudo.annotation.UseAnnDemo");
        Method[] methods = useAnnClz.getMethods();
        for(Method method: methods){
            String methodName = method.getName();
            System.out.println("analyzing method:" + methodName);
            Annotation[] anns = method.getAnnotations();
            SimpleAnnotation simpleAnnotation = method.getAnnotation(SimpleAnnotation.class);
            if(null != simpleAnnotation){
                // 一般在这里面分析注解的属性值,然后根据注解属性的取值,决定程序接下来的操作
                System.out.println("----> ann name:" + simpleAnnotation.name() + " value:" + simpleAnnotation.value());
            }
            //method.getAnnotationsByType(annotationClass)
            // for(Annotation ann : anns){
            //     Class annotationType = ann.annotationType();
            //     System.out.println("annotationType:"+annotationType.getName());
            // }
        }
    }
}
